package cn.fuxi2022.module.pay.properties;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * 微信支付配置 + 社费配置
 */
@Component
public class WeChatPayProperties implements InitializingBean {

    @Value("${wx.pay.mch_id}")
    private String mchId;

    @Value("${wx.pay.notify_url}")
    private String notify_url;

    @Value("${smartGroup.price}")
    private String studentPrice;

    @Value("${smartGroup.body}")
    private String body;

    /**
     * 商户号ID
     */
    public static String MCH_ID;

    /**
     * 支付成功后的回调地址
     */
    public static String NOTIFY_URL;

    /**
     * 当前社团支付社费的价格
     */
    public static String STUDENT_PRICE;


    /**
     * 商品描述
     */
    public static String SHOP_BODY;

    /**
     * 字段名：终端IP.
     * 描述：APP和网页支付提交用户端ip，Native支付填调用微信支付API的机器IP。
     */
    public static String SPBILL_CREATEIP = "0.0.0.0";

    /**
     * 退款原因
     */
    public static String REFUND_DESC = "管理员在社团系统手动退款该订单";


    @Override
    public void afterPropertiesSet() throws Exception {
        MCH_ID = mchId;
        STUDENT_PRICE = BigDecimal.valueOf(Double.parseDouble(studentPrice)).multiply(BigDecimal.valueOf(100)).stripTrailingZeros().toPlainString();
        NOTIFY_URL = notify_url;
        SHOP_BODY = body;
    }
}